package com.wiseMen.wechat.user;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wiseMen.platform.utils.AjaxUtils;
import com.wiseMen.platform.utils.PageUtils;

@Controller
@RequestMapping("/wechat/user")
public class WechatUserAction {
	
	@Autowired
	private WechatUserService service;
	
	@RequestMapping("/index")
	public String Index(){
		return "/wechat/user/Index";
	}
	
	@RequestMapping("/listpage")
    @ResponseBody
    public Object listpage(WechatUserEntity entity) {
        List<WechatUserEntity> list = service.listpage(PageUtils.getPageRequestInfo(),entity);
        return PageUtils.getPageResultInfo(list);
    }
	
	@RequestMapping("/syncUserInfos")
    @ResponseBody
    public Object syncUserInfos(String openIds) {
		try{
			if(StringUtils.isNotBlank(openIds)){
				service.syncUserInfos(openIds.split(","));
				return AjaxUtils.renderJsonInfo(true, "同步成功", null, null);
			}else{
				return AjaxUtils.renderJsonInfo(false, "关键参数为空", null, null);
			}
		}catch(Exception ex){
			ex.printStackTrace();
			return AjaxUtils.renderJsonInfo(false, "同步失败："+ex.getMessage(), null, null);
		}
    }
	
	@RequestMapping("/syncAllUser")
    @ResponseBody
    public Object syncAllUser() {
		try{
			service.syncAllUser();
			return AjaxUtils.renderJsonInfo(true, "同步成功", null, null);
		}catch(Exception ex){
			ex.printStackTrace();
			return AjaxUtils.renderJsonInfo(false, "同步失败："+ex.getMessage(), null, null);
		}
    }
}
